package com.ruoyi.operation.order.amount.controller;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.operation.order.amount.domain.Amount;
import com.ruoyi.operation.order.amount.service.IAmountService;
import com.ruoyi.operation.order.depot.domain.Depot;
import com.ruoyi.operation.order.enter.service.IEnterFormService;
import com.ruoyi.operation.order.product.domain.Product;
import com.ruoyi.operation.order.product.service.IProductService;
import com.ruoyi.project.system.dept.domain.Dept;
import com.ruoyi.project.system.dept.service.IDeptService;
import com.ruoyi.project.system.role.service.IRoleService;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.service.IUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author king
 * @create 2019/4/13 21:39
 */
@RequestMapping(value = "/account/account")
@Controller
public class AmountController extends BaseController {

    // 定义一个跳转到页面的路径
    private String prefix = "order/amount/";

    @Autowired
    private IUserService iUserService;

    @Autowired
    private IRoleService iRoleService;

    @Autowired
    private IAmountService iAmountService;

    @Autowired
    private IProductService iProductService;

    @Autowired
    private IDeptService iDeptService;




    /**
     * 跳转到核销账目页面
     * @return
     */
    @RequiresPermissions(value = "account:account:account")
    @GetMapping()
    String amount(){
        return prefix + "amount";
    }


    /**
     * 查询所有的核销账目列表的信息
     * @param amount
     * @return
     */
    @RequestMapping(value = "/list")
    @RequiresPermissions(value = "account:account:account")
    @ResponseBody
    public TableDataInfo allAmountList(Amount amount){

        // 获取当前登陆人的id
//        String getUserId = ShiroUtils.getLoginId();
        // 更具当前登陆人获取roleId
//        String getRoleId = iRoleService.getRoleId(getUserId);
//        if (getRoleId.equals("1") || getRoleId.equals("5")){
//            // 此时是超级管理员和鹰之队的管理员
//            amount.setType("1");
//        }else if(getRoleId.equals("3")){
//            amount.setType("2");
//            // 根据id获取对应的部门id
//            String getDeptId = iUserService.getDeptId(getUserId);
//            amount.setDeptId(getDeptId);
//        } else if(getRoleId.equals("4")){
//            // 此时是登陆人
//            amount.setType("3");
//            amount.setCreateBy(getUserId);
//        }
        startPage();
        List<Amount> amountList = iAmountService.allAmountList(amount);
        return getDataTable(amountList);
    }


    /**
     * 获取对应人在对应平台的订单数量
     * @param userId
     * @param productId
     * @return
     */
    @RequestMapping(value = "/getEenterNumCount")
    @ResponseBody
    public String getEenterNumCount(String deptId,String userId,String productId,String beginTime,String endTime){
        // 获取对应人在对应平台的的产品名称的订单数量
        String getEenterNumCount = iAmountService.getEenterNumCount(deptId,userId,productId,beginTime,endTime);
        return getEenterNumCount;
    }

    /**
     * 获取所有的订单价格
     * @param deptId
     * @param userId
     * @param productId
     * @param beginTime
     * @param endTime
     * @param orderPrice
     * @return
     */
    @RequestMapping(value = "/getEnterPriceCount")
    @ResponseBody
    public String getEnterPriceCount(String deptId,String userId,String productId,String beginTime,String endTime,String orderPrice ){
        // 获取订单数量
        Integer getEenterNumCount = Integer.parseInt(iAmountService.getEenterNumCount(deptId,userId,productId,beginTime,endTime));
        Integer getEnterPriceCount = getEenterNumCount * Integer.parseInt(orderPrice);
        return getEnterPriceCount.toString();
    }
    /**
     * 获取所有的订单价格
     * @param deptId
     * @param userId
     * @param productId
     * @param beginTime
     * @param endTime
     * @param commission
     * @return
     */
    @RequestMapping(value = "/getCommissionCount")
    @ResponseBody
    public String getCommissionCount(String deptId,String userId,String productId,String beginTime,String endTime,String commission ){
        // 获取订单数量
        Integer getEenterNumCount = Integer.parseInt(iAmountService.getEenterNumCount(deptId,userId,productId,beginTime,endTime));
        Integer getCommissionCount = getEenterNumCount * Integer.parseInt(commission);
        return getCommissionCount.toString();
    }
    /**
     * 获取所有的好评
     * @param deptId
     * @param userId
     * @param productId
     * @param beginTime
     * @param endTime
     * @param goodPrice
     * @return
     */
    @RequestMapping(value = "/getGoodRecordPriceCount")
    @ResponseBody
    public String getGoodRecordPriceCount(String deptId,String userId,String productId,String beginTime,String endTime,String goodPrice ){
        // 获取所有的好评的数量
        Integer getGoodRecordPriceCount = iAmountService.getGoodRecordPriceCount(deptId,userId,productId,beginTime,endTime);
        if(getGoodRecordPriceCount!=0){
            Integer getGoodRecordPriceCountT = getGoodRecordPriceCount * Integer.parseInt(goodPrice);
            return getGoodRecordPriceCountT.toString();
        }else{
            return "0";
        }

    }


    /**
     * 查询所有的产品信息
     * @return
     */
    @RequestMapping(value = "/allProduct")
    @ResponseBody
    public List<Product> allProduct(){
        return iProductService.allProduct();
    }

    /**
     * 查询所有的平台
     * @return
     */
    @RequestMapping(value = "/allDeptT")
    @ResponseBody
    public List<Dept> allDeptT(){
        return iDeptService.allDeptList();
    }

    /**
     * 查询所有的录单员
     * @return
     */
    @RequestMapping(value = "/getUserByRoeId")
    @ResponseBody
    public List<User> getUserByRoeId(){
        return iUserService.getUserByRoleId();
    }

    /**
     * 导出订单信息
     * @param amount
     * @param request
     * @param response
     * @throws Exception
     */
    @RequestMapping(value = "/exportExcel")
    public void exportExcel(Amount amount, HttpServletRequest request, HttpServletResponse response) throws Exception{
        iAmountService.exportDepot(amount,request,response);
    }


}
